package com.iwdnb.gkgz.application.strategy;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.iwdnb.bmnf.common.utils.BooleanUtils;
import com.iwdnb.gkgz.application.model.request.AddStrategyTradeStockDataRequest;
import com.iwdnb.gkgz.application.model.vo.StrategyTradeScore;
import com.iwdnb.gkgz.application.model.vo.StrategyTradeScoreInfo;
import com.iwdnb.gkgz.application.utils.StockScoreUtils;
import com.iwdnb.gkgz.common.enums.StockSecondIndustryEnums;
import com.iwdnb.gkgz.common.model.dto.Stock;
import com.iwdnb.gkgz.common.model.dto.TldCheckInfo;
import com.iwdnb.gkgz.common.model.dto.TldMatchInfo.TldMatchItem;
import com.iwdnb.gkgz.common.quota.VolumeRatioIndicator;
import com.iwdnb.gkgz.common.utils.TulongdaoUtils;
import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.model.dto.StrategyTradeDTO;
import com.iwdnb.gkgz.common.quota.MacdIndicator;
import com.iwdnb.gkgz.common.quota.MovingAverage;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import com.iwdnb.gkgz.common.utils.DateUtils;
import com.iwdnb.gkgz.common.utils.StockUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import static com.iwdnb.gkgz.common.utils.StockUtils.getAveragePrice;
import static com.iwdnb.gkgz.common.utils.StockUtils.isLimitUp;
import static com.iwdnb.gkgz.common.utils.StockUtils.isOneLineStock;
import static com.iwdnb.gkgz.common.utils.BigDecimalUtils.of;

/**
 * 屠龙刀战法
 * 第二天成交量比涨停板减半的买入信号，单次盈利1.0%，很低
 */
@Service
@Slf4j
public class TulongdaoStockBackValidateService extends CommmonStockBackValidateService {

    public static final String STATEGY_CODE = "tulongdao";

    private BigDecimal fuFive = new BigDecimal(-5);
    private BigDecimal sixPointFive = new BigDecimal(6.5);

    @Override
    public List<StrategyTradeDTO> queryBackValidateDateList(String code, String strategy,
        List<StockDayData> stockDayDataList, AddStrategyTradeStockDataRequest request) {
        boolean ignoreLowScoreFlag = BooleanUtils.isTrue(request.getIgnoreLowScoreFlag());
        if (CollectionUtils.isEmpty(request.getTradeScoreList())) {
            List<StrategyTradeScore> tradeScoreList = getInitTradeScoreList();
            request.setTradeScoreList(tradeScoreList);
        }
        Stock stock = StockUtils.getStock(code);
        if (StockSecondIndustryEnums.isBlackIndustry(stock.getSecondIndustry())) {
            log.info("{} is isBlackIndustry,ignore", code);
            return null;
        }
        if (CollectionUtils.isEmpty(stockDayDataList)) {
            return null;
        }
        MovingAverage.calculateEMA(stockDayDataList, ALL_PERIODS);
        MacdIndicator.calculateMACD(stockDayDataList);
        VolumeRatioIndicator.calculateVolumeRatio(stockDayDataList);
        List<String> dateList = new ArrayList<>();
        List<StrategyTradeDTO> strategyTradeDTOList = new ArrayList<>();
        for (int i = 0; i < stockDayDataList.size(); i++) {
            if (i < 800) {
                continue;
            }
            StockDayData data = stockDayDataList.get(i);
            String date = data.getDate();
            if (BigDecimalUtils.isLe(data.getOpenPrice(), BigDecimal.ONE)) {
                continue;
            }
            if (!isLimitUp(data)) {
                continue;
            }
            if (isOneLineStock(data)) {
                continue;
            }

            TldCheckInfo checkInfo = TulongdaoUtils.checkTldMacthInfo(code, stockDayDataList, date);
            if (Objects.isNull(checkInfo)) {
                continue;
            }
            StockDayData afterLowData = checkInfo.getMatchData();
            TldMatchItem tldMatchItem = checkInfo.getMatchInfo().getMatchItem();
            String afterLowDate = afterLowData.getDate();
            if (!dateList.contains(afterLowDate)) {
                dateList.add(afterLowDate);
                StrategyTradeDTO strategyTradeDTO = new StrategyTradeDTO();
                strategyTradeDTO.setCode(code);
                strategyTradeDTO.setUuid(STATEGY_CODE);
                strategyTradeDTO.setBuyDate(DateUtil.parseDate(afterLowDate));
                strategyTradeDTO.setBuyData(afterLowData);
                //strategyTradeDTO.setStockImageProfitType(stockImageProfitType);
                strategyTradeDTO.setStockImageCode(checkInfo.getStockImageValue() + "");
                //买入价为匹配均线上方1个点
                BigDecimal buyPrice = tldMatchItem.getBuyPrice();
                BigDecimal buyMinRate = BigDecimalUtils.subStractAndDividePrecent(buyPrice, afterLowData.getMinPrice());

                strategyTradeDTO.setBuyPrice(buyPrice);
                strategyTradeDTO.setBuyMinPrice(afterLowData.getMinPrice());
                strategyTradeDTO.setStatus("buy");
                BigDecimal limitSellPrice = BigDecimalUtils.multiply(buyPrice, BigDecimalUtils.zeroPointNineSeven);
                strategyTradeDTO.setLimitSellPrice(limitSellPrice);
                strategyTradeDTO.setSignalPrice(tldMatchItem.getAvg());
                //买入价与涨停板跌幅
                strategyTradeDTO.setBuySignalRate(checkInfo.getBuyRate());
                //买入价与当天最低点跌幅
                strategyTradeDTO.setBuySignalMinRate(
                    BigDecimalUtils.subStractAndDividePrecent(strategyTradeDTO.getBuyPrice(),
                        strategyTradeDTO.getBuyMinPrice()));
                strategyTradeDTO.setSummary(afterLowData.getRemark());
                strategyTradeDTO.setClosePrice(data.getClosePrice());
                //买入限制价格,涨停板开盘价与前一日收盘价的更低价的值
                strategyTradeDTO.setLimitPrice(checkInfo.getLimitPrice());
                //买入日信息
                strategyTradeDTO.setV5(
                    BigDecimalUtils.subStractAndDividePrecent(afterLowData.getClosePrice(), buyPrice));
                //买入日开盘价与买入价之差
                strategyTradeDTO.setV6(
                    BigDecimalUtils.subStractAndDividePrecent(afterLowData.getOpenPrice(), buyPrice));
                //涨停板最低价与前一日收盘价价差
                strategyTradeDTO.setDataMinPriceRate(checkInfo.getDataMinPriceRate());
                //涨停后第几天买入
                strategyTradeDTO.setBuyDayIndex(checkInfo.getMatchInfo().getIndex());
                //均线
                strategyTradeDTO.setBuyPeriod(tldMatchItem.getPeriod().toString());
                //strategyTradeDTO.setV12(afterLowData.getAvarage().getBigDecimal("10"));
                //strategyTradeDTO.setV13(afterLowData.getAvarage().getBigDecimal("20"));
                //strategyTradeDTO.setV14(afterLowData.getAvarage().getBigDecimal("30"));
                //strategyTradeDTO.setV15(afterLowData.getAvarage().getBigDecimal("60"));

                //涨停板后次日信息
                StockDayData afterOneData = checkInfo.getAfterOneData();
                strategyTradeDTO.setAfterOneMaxPriceRate(checkInfo.getAfterOneMaxPriceRate());
                strategyTradeDTO.setAfterOneRate(afterOneData.getRate());
                strategyTradeDTO.setAfterOneUpLineRate(checkInfo.getAfterOneUplineRate());
                strategyTradeDTO.setAfterOneDownLineRate(StockUtils.caculateDownLineRate(afterOneData));
                strategyTradeDTO.setAfterOneOpenCloseRate(StockUtils.caculateRangeRate(afterOneData));
                //涨停板后2日
                StockDayData afterTwoData = checkInfo.getAfterTwoData();
                strategyTradeDTO.setAfterTwoMaxPriceRate(
                    BigDecimalUtils.subStractAndDividePrecent(afterTwoData.getMaxPrice(), data.getClosePrice()));
                strategyTradeDTO.setAfterTwoRate(afterTwoData.getRate());
                strategyTradeDTO.setAfterTwoUpLineRate(StockUtils.caculateUpLineRate(afterTwoData));
                strategyTradeDTO.setAfterTwoDownLineRate(StockUtils.caculateDownLineRate(afterTwoData));
                strategyTradeDTO.setAfterTwoOpenCloseRate(StockUtils.caculateRangeRate(afterTwoData));

                //成交量以涨停板为1做对比
                BigDecimal tradeNum = of(data.getTradeNum());
                strategyTradeDTO.setV35(
                    BigDecimalUtils.divide(of(checkInfo.getBeforeTwoData().getTradeNum()), tradeNum));
                strategyTradeDTO.setV36(
                    BigDecimalUtils.divide(of(checkInfo.getBeforeOneData().getTradeNum()), tradeNum));
                strategyTradeDTO.setV37(BigDecimalUtils.divide(of(afterOneData.getTradeNum()), tradeNum));
                strategyTradeDTO.setV38(BigDecimalUtils.divide(of(afterTwoData.getTradeNum()), tradeNum));

                //strategyTradeDTO.setV13(afterThreeData.getClosePrice());
                //strategyTradeDTO.setV14(new BigDecimal(afterThreeData.getTradeNum()));
                //strategyTradeDTO.setV15(afterThreeData.getMaxPrice());
                //strategyTradeDTO.setV16(
                //    BigDecimalUtils.subStractAndDividePrecent(afterThreeData.getMaxPrice(),
                //        afterThreeData.getMinPrice()));
                //strategyTradeDTO.setV19(new BigDecimal(afterLowData.getMatchIndex()));
                //strategyTradeDTO.setV20(new BigDecimal(afterLowData.getMatchPeriod()));
                //strategyTradeDTO.setV21(beforeFourtyLowRate);
                //strategyTradeDTO.setV22(beforeTwentyLowRate);
                //strategyTradeDTO.setV23(beforeTenLowRate);
                //strategyTradeDTO.setV24(beforeTenHighRate);
                //strategyTradeDTO.setV25(beforeFiveHighRate);
                //strategyTradeDTO.setV26(BigDecimalUtils.of(beforeFiftyLimitUpCount));
                //strategyTradeDTO.setV27(BigDecimalUtils.of(beforeFiftyMultyLimitUpCount));
                //买入价距离涨停板最低价的比值
                //strategyTradeDTO.setV28(buyMinRate);
                //strategyTradeDTO.setV29(afterLowData.getRate());
                //BigDecimal lowPrice = BigDecimalUtils.isGt(data.getRate(), zero) ? data.getOpenPrice()
                //    : data.getClosePrice();
                //BigDecimal lowRate = BigDecimalUtils.subStractAndDividePrecent(lowPrice, afterLowData.getMinPrice());
                //strategyTradeDTO.setV30(lowRate);
                //成交量信息
                strategyTradeDTO.setV41(checkInfo.getBeforeTwoVolumeRatio());
                strategyTradeDTO.setV42(checkInfo.getBeforeOneVolumeRatio());
                strategyTradeDTO.setV43(checkInfo.getDataVolumeRatio());
                strategyTradeDTO.setV44(checkInfo.getAfterOneVolumeRatio());
                strategyTradeDTO.setV45(checkInfo.getAfterTwoVolumeRatio());
                //strategyTradeDTO.setV46(StockUtils.getStockQuota(afterThreeData, VolumeRatioIndicator.QUOTA_NAME));
                strategyTradeDTO.setV47(StockUtils.getStockQuota(afterLowData, VolumeRatioIndicator.QUOTA_NAME));

                //均线角度
                strategyTradeDTO.setAvgRate10(checkInfo.getAvgRate10());
                strategyTradeDTO.setAvgRate20(checkInfo.getAvgRate20());
                strategyTradeDTO.setAvgRate30(checkInfo.getAvgRate30());
                strategyTradeDTO.setAvgRate60(checkInfo.getAvgRate60());
                //买入价与均线差幅
                strategyTradeDTO.setBuyAvgRate10(checkInfo.getBuyAvgRate10());
                strategyTradeDTO.setBuyAvgRate20(checkInfo.getBuyAvgRate20());
                strategyTradeDTO.setBuyAvgRate30(checkInfo.getBuyAvgRate30());
                strategyTradeDTO.setBuyAvgRate60(checkInfo.getBuyAvgRate60());
                //strategyTradeDTO.setV55(checkInfo.getAfterTwoAvgRate10());
                //strategyTradeDTO.setV56(checkInfo.getAfterTwoAvgRate20());
                //strategyTradeDTO.setV57(checkInfo.getAfterTwoAvgRate30());
                //strategyTradeDTO.setV58(checkInfo.getAfterTwoAvgRate60());
                //Macd macd = afterLowData.getMacd();
                //strategyTradeDTO.setV34(macd.getDif());
                //strategyTradeDTO.setV35(macd.getDea());
                //strategyTradeDTO.setV36(macd.getBar());
                //BigDecimal afterMaxPrice = StockUtils.getMaxPriceAfterDate(stockDayDataList, date, 10);
                //strategyTradeDTO.setV37(
                //    BigDecimalUtils.subStractAndDividePrecent(afterMaxPrice, afterLowData.getClosePrice()));
                //BigDecimal afterMinPrice = StockUtils.getMinPriceAfterDate(stockDayDataList, date, 10);
                //strategyTradeDTO.setV38(
                //    BigDecimalUtils.subStractAndDividePrecent(afterLowData.getClosePrice(), afterMinPrice));
                //20日内涨幅
                strategyTradeDTO.setBeforeTwentyRate(checkInfo.getBeforeTwentyRate());
                //20日内涨停次数
                strategyTradeDTO.setBeforeTwentyLimitUpCount(checkInfo.getBeforeTwentyLimitUpCount());
                //涨停前2日到后2日的成交量比值编号
                strategyTradeDTO.setTradeNumRatioCode(checkInfo.getTradeNumRatioCode());
                //是否开盘命中
                strategyTradeDTO.setMatchOpenFlag(tldMatchItem.getOpenMatchFlag());
                strategyTradeDTO.setStockImageValue(checkInfo.getStockImageValue());
                strategyTradeDTO.setAfterOneOpenCloseRate(checkInfo.getAfterOneOpenCloseRate());
                StrategyTradeScoreInfo scoreInfo = StockScoreUtils.calculateTradeScore(strategyTradeDTO,
                    request.getTradeScoreList());
                strategyTradeDTO.setScore(scoreInfo.getScore());
                //校验下评分,
                if (ignoreLowScoreFlag && BigDecimalUtils.isLe(strategyTradeDTO.getScore(),
                    BigDecimalUtils.onePointSix)) {
                    log.info("{}-{}-{}-股票评分过低:{},忽略", code, StockUtils.getStock(code).getName(), data.getDate(),
                        strategyTradeDTO.getScore());
                    continue;
                }
                strategyTradeDTOList.add(strategyTradeDTO);
            }
        }
        return strategyTradeDTOList;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void doBackValidate(String code, String strategy, List<StockDayData> stockDayDataList,
        List<StrategyTradeDTO> strategyTradeDTOList) {
        List<String> dateList = strategyTradeDTOList.stream().map(o -> DateUtil.formatDate(o.getBuyDate())).collect(
            Collectors.toList());
        Date latestEndDate = DateUtil.parseDate(dateList.get(0));
        latestEndDate = DateUtil.offsetDay(latestEndDate, -1);
        for (StrategyTradeDTO strategyTradeDTO : strategyTradeDTOList) {
            Date d = strategyTradeDTO.getBuyDate();
            if (DateUtils.beforeOrEquals(d, latestEndDate)) {
                log.debug("{}-{}在上一个周期内,忽略", code, d);
                continue;
            }
            getTradeInfo(code, stockDayDataList, strategyTradeDTO);
            latestEndDate = strategyTradeDTO.getSellDate();
        }
    }

    private void getTradeInfo(String code, List<StockDayData> stockDayDataList, StrategyTradeDTO strategyTradeDTO) {
        String date = DateUtil.formatDate(strategyTradeDTO.getBuyDate());
        //log.debug("{}-{}>>>>>股票信息:{}", code, date, strategyTradeDTO.getSummary());
        StockDayData buyDayData = StockUtils.getStockDayData(stockDayDataList, date);
        BigDecimal buyPrice = strategyTradeDTO.getBuyPrice();
        List<StockDayData> subList = StockUtils.getStockDayDataListAfterDate(stockDayDataList, date, 100);
        if (CollectionUtils.isEmpty(subList) || subList.size() < 2) {
            return;
        }
        int size = subList.size();
        StockDayData firtData = subList.get(0);
        String firstDate = firtData.getDate();
        BigDecimal closeRate = null;
        String sellDate = null;
        String info = "";
        BigDecimal sellPrice = null;
        BigDecimal rate = closeRate;
        int holdIndex = 0;
        BigDecimal rangeMaxPrice = strategyTradeDTO.getBuyPrice();
        BigDecimal rangeMaxRate = BigDecimal.ZERO;
        int rangeMaxIndex = 0;
        BigDecimal rangeCloseMaxPrice = strategyTradeDTO.getBuyPrice();
        BigDecimal rangeCloseMaxRate = BigDecimal.ZERO;
        BigDecimal rangeMinPrice = strategyTradeDTO.getBuyPrice();
        BigDecimal rangeMinRate = BigDecimal.ZERO;
        int rangeMinIndex = 0;
        for (int i = 0; i < 10; i++) {
            if (i == size) {
                return;
            }
            StockDayData data = subList.get(i);
            //计算长上影线
            BigDecimal upPrice = BigDecimalUtils.isGt(data.getRate(), zero) ? data.getClosePrice()
                : data.getOpenPrice();
            BigDecimal highRate = BigDecimalUtils.subStractAndDividePrecent(data.getMaxPrice(), upPrice);
            //if (i == 0) {
            //    strategyTradeDTO.setV17(BigDecimalUtils.subStractAndDividePrecent(data.getOpenPrice(),
            //        strategyTradeDTO.getBuyData().getClosePrice()));
            //    strategyTradeDTO.setV18(highRate);
            //}
            StockDayData yesterdayDayData = i == 0 ? data : subList.get(i - 1);
            BigDecimal closePrice = data.getClosePrice();
            closeRate = BigDecimalUtils.subStractAndDividePrecent(closePrice, buyPrice);
            sellDate = data.getDate();
            sellPrice = data.getClosePrice();
            holdIndex = i;
            BigDecimal upRate = BigDecimalUtils.subStractAndDividePrecent(data.getMaxPrice(), buyPrice);
            BigDecimal openRange = data.getOpenPrice().subtract(buyPrice);
            BigDecimal openRate = BigDecimalUtils.divideToPrecent(openRange, buyPrice);
            if (BigDecimalUtils.isGt(data.getMaxPrice(), rangeMaxPrice)) {
                rangeMaxPrice = data.getMaxPrice();
                rangeMaxRate = BigDecimalUtils.subStractAndDividePrecent(rangeMaxPrice, buyPrice);
                rangeMaxIndex = i;
            }
            if (BigDecimalUtils.isLt(data.getMinPrice(), rangeMinPrice)) {
                rangeMinPrice = data.getMinPrice();
                rangeMinRate = BigDecimalUtils.subStractAndDividePrecent(rangeMinPrice, buyPrice);
                rangeMinIndex = i;
            }
            rangeCloseMaxPrice = BigDecimalUtils.isGt(data.getClosePrice(), rangeCloseMaxPrice) ? data.getClosePrice()
                : rangeCloseMaxPrice;
            rangeCloseMaxRate = BigDecimalUtils.subStractAndDividePrecent(rangeCloseMaxPrice, buyPrice);

            BigDecimal realtimeRate = BigDecimalUtils.subStractAndDividePrecent(data.getClosePrice(), buyPrice);
            rate = closeRate;
            String sellInfo = "收盘价卖出";
            // 跌破止损价，跑路
            if (BigDecimalUtils.isLt(data.getOpenPrice(), strategyTradeDTO.getLimitSellPrice())) {
                sellInfo = "开盘跌破止损价,止损";
                rate = BigDecimalUtils.subStractAndDividePrecent(data.getOpenPrice(), buyPrice);
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }
            if (BigDecimalUtils.isLt(data.getClosePrice(), strategyTradeDTO.getLimitSellPrice())) {
                sellInfo = "跌破止损价,止损";
                rate = BigDecimalUtils.subStractAndDividePrecent(strategyTradeDTO.getLimitSellPrice(), buyPrice);
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }
            if (isLimitUp(data)) {
                info += "第" + (i + 1) + "天涨停,拿住;";
                continue;
            }
            ////有长上影线,就在上影线一半的位置卖掉
            //if (BigDecimalUtils.isGe(highRate, four)) {
            //    BigDecimal price = BigDecimalUtils.add(data.getMaxPrice(), upPrice);
            //    sellPrice = BigDecimalUtils.divide(price, two);
            //    BigDecimalUtils.subStractAndDividePrecent(sellPrice, buyPrice);
            //    sellInfo = "冲高卖出";
            //    log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo,
            //    rate,
            //        openRate, closeRate, upRate);
            //    info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
            //        + ",最高点收益=" + upRate;
            //    break;
            //}

            //收盘价卖出
            log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                openRate, closeRate, upRate);
            sellInfo = "收盘价正常卖出";
            info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                + ",最高点收益=" + upRate;
            break;
        }
        strategyTradeDTO.setHoldDay(holdIndex + 1);
        strategyTradeDTO.setSellDate(DateUtil.parseDate(sellDate));
        strategyTradeDTO.setSellPrice(sellPrice);
        strategyTradeDTO.setProfitRate(rate);
        strategyTradeDTO.setRangeMaxPrice(rangeMaxPrice);
        strategyTradeDTO.setRangeMaxRate(rangeMaxRate);
        strategyTradeDTO.setRangeMinPrice(rangeMinPrice);
        strategyTradeDTO.setRangeMinRate(rangeMinRate);
        String downBuyPriceInfo = BigDecimalUtils.isLt(rangeMinPrice, strategyTradeDTO.getBuyMinPrice()) ? "有" : "未";
        StockDayData maxData = subList.get(rangeMaxIndex);
        BigDecimal highRate = BigDecimalUtils.subStractAndDividePrecent(maxData.getMaxPrice(), maxData.getClosePrice());
        String rangeInfo = "第" + (rangeMinIndex + 1) + "天为最低价," + downBuyPriceInfo + "跌破买入价,第" + (rangeMaxIndex + 1)
            + "天为最高价,与收盘价差为" + highRate + "%;";
        strategyTradeDTO.setFollowInfo(rangeInfo);
        strategyTradeDTO.setStrategyDescription(info);
        strategyTradeDTO.setStatus("sell");
        strategyTradeDTO.setWinFlag(BigDecimalUtils.isGt(rate, BigDecimal.ZERO) ? "y" : "n");
        //是否跌破止损价
        //strategyTradeDTO.setV19(BigDecimalUtils.isLt(rangeMinPrice, strategyTradeDTO.getLimitSellPrice()) ? one :
        // zero);
        //strategyTradeDTO.setV20(highRate);
    }

}
